package com.fm.openinstall.e;

import android.content.*;
import java.util.concurrent.*;
import android.os.*;
import android.text.*;
import com.fm.openinstall.f.*;

public class f
{
    private static volatile f a;
    private LinkedBlockingQueue b;
    private c c;
    private Long d;
    private Context e;
    private ExecutorService f;
    private Object g;
    private volatile boolean h;
    private Thread i;
    private a j;
    private long k;
    private boolean l;

    private f(final Context e) {
        this.b = new LinkedBlockingQueue(1);
        this.c = com.fm.openinstall.f.c.a(f.class);
        this.d = null;
        this.g = new Object();
        this.h = true;
        this.e = e;
        this.k = System.currentTimeMillis();
        this.l = com.fm.openinstall.f.d.b(this.e, "FM_first_background", true);
        this.f = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(30), new g(this), new h(this));
        this.i = new Thread(new i(this));
        a j;
        if (Build.VERSION.SDK_INT >= 14) {
            j = new b(this.e, this);
        }
        else {
            j = new com.fm.openinstall.e.d(this.e, this);
        }
        this.j = j;
    }

    public static f a(final Context context) {
        if (f.a == null) {
            synchronized (f.class) {
                if (f.a == null) {
                    f.a = new f(context);
                }
            }
        }
        return f.a;
    }

    private void a(final String s) {
        this.f.execute(new j(this, s));
    }

    private boolean d() {
        final Long d = this.d;
        boolean b = false;
        if (d == null) {
            return false;
        }
        if (this.d * 1000L < System.currentTimeMillis() - this.k) {
            b = true;
        }
        return b;
    }

    private void e() {
        this.f.execute(new k(this));
    }

    public void a() {
        this.h = true;
        this.i.start();
        this.j.a();
    }

    public void a(final long n) {
        this.d = n;
    }

    public void a(final String s, final long n) {
        if (!TextUtils.isEmpty((CharSequence)s)) {
            final long currentTimeMillis = System.currentTimeMillis();
            final StringBuilder sb = new StringBuilder();
            sb.append(s);
            sb.append(",");
            sb.append(currentTimeMillis);
            sb.append(",");
            sb.append(n);
            sb.append(";");
            this.a(sb.toString());
        }
    }

    public void b() {
        this.h = false;
        this.j.b();
    }

    public void b(final long n) {
        if (n > 1L) {
            final long currentTimeMillis = System.currentTimeMillis();
            final StringBuilder sb = new StringBuilder();
            sb.append(currentTimeMillis);
            sb.append(",");
            sb.append(n);
            sb.append(";");
            this.a(sb.toString());
            if (this.l) {
                this.e();
                com.fm.openinstall.f.d.a(this.e, "FM_first_background", false);
                this.l = false;
            }
        }
    }

    public void c() {
        com.fm.openinstall.f.e.b(this.e, "AliveLog.txt");
        this.k = System.currentTimeMillis();
    }
}
